
gpNamespace.ScJumpLayer = cc.Layer.extend({
	page:null,//商城第几页
	type: null,//消费类型
	num:1,//购买数量
	goods:null,
//	target: null,
//	args: [],
	numBg:null,
	price:null,
	ctor:function(page,type,goods){
		this._super();
		this.page = page;
		this.type = type;
		this.goods = goods;
//		this.target = target;
//		if (args != undefined)
//			this.args = args;
		
		this.init();
	},
	init: function () {
		//商城弹窗
		cc.spriteFrameCache.addSpriteFrames(gpNamespace.sctcRes.Sctc_plist);
		//各种数字
		cc.spriteFrameCache.addSpriteFrames(gpNamespace.jsnumRes.Jsnum_plist);
		//新弹窗
		cc.spriteFrameCache.addSpriteFrames(gpNamespace.pdkTanKuangRes.tankuang_plist);
		
		var background = new cc.Sprite(gpNamespace.tankuang.backgroundBig);
		background.attr({
			x:cc.winSize.width/2,
			y:cc.winSize.height/2,
			anchorX:0.5,
			anchorY:0.5
		});
		this.addChild(background);

		var words = new cc.Sprite(gpNamespace.sctc.Sctc_WordsPic);
		words.attr({
			x:150,
			y:270,
			anchorX:0,
			anchorY:0
		});
		background.addChild(words);

		//消费类型
		var moneyTypePic = null;
		if(this.page == 2 || this.page == 3){
			if(this.goods[6] == 1){
				moneyTypePic = gpNamespace.sctc.Sctc_Diamond;
			}else if(this.goods[6] == 2){
				moneyTypePic = gpNamespace.sctc.Sctc_Voucher;
			}else if(this.goods[6] == 0){
				moneyTypePic = gpNamespace.sctc.Sctc_Gold;
			}
		}else{
			moneyTypePic =  gpNamespace.sctc.Sctc_Gold;
			if(this.type == 0){
				moneyTypePic = gpNamespace.sctc.Sctc_Gold;
			}else if(this.type == 1){
				moneyTypePic = gpNamespace.sctc.Sctc_Diamond;
			}else if(this.type == 2){
				moneyTypePic = gpNamespace.sctc.Sctc_Voucher;
			}
		}
		
		var moneyPic = new cc.Sprite(moneyTypePic);
		moneyPic.attr({
			x:372,
			y:325,
			anchorX:0,
			anchorY:0
		});
		background.addChild(moneyPic);

		//价格
		var price = new tyNamespace.NumLayer(this.goods[2],21,13,"sz_cdd_js_");
		price.attr({
			x:500,
			y:358,
			anchorX:0,
			anchorY:0.5
		});
		this.price = price;
		background.addChild(price);

		//數量背景
		var numBg = new cc.Sprite(gpNamespace.tankuang.edittextbg);
		numBg.attr({
			x:224,
			y:170,
			anchorX:0,
			anchorY:0
		});
		this.numBg = numBg;
		background.addChild(numBg);
		
		//數量
		var num = new tyNamespace.NumLayer(this.num,21,13,"sz_cdd_js_");
		num.setTag(110)
		num.attr({
			x:645,
			y:300,
		});
		this.addChild(num);

		//名称
		var goodsName = new cc.LabelTTF(this.goods[8],gpNamespace.DEFAULTFONT,30);
		goodsName.setFontFillColor(cc.color(108, 28, 11, 255));
		goodsName.attr({
			x:266,
			y:290,
			anchorX:0,
			anchorY:0.5
		});
		this.goodsName = goodsName;
		background.addChild(goodsName);
		
		//min
		var minPic = new cc.MenuItemImage(gpNamespace.sctc.Sctc_Sub2Min,gpNamespace.sctc.Sctc_Sub2Min,this.sub2minCallback,this);
		minPic.attr({
			x:56,
			y:172,
			anchorX:0,
			anchorY:0
		});
		minPic.setUserData(this);
		
		//max
		var maxPic = new cc.MenuItemImage(gpNamespace.sctc.Sctc_Add2Max,gpNamespace.sctc.Sctc_Add2Max,this.add2maxCallback,this);
		maxPic.attr({
			x:608,
			y:172,
			anchorX:0,
			anchorY:0
		});
		maxPic.setUserData(this);
		
		//sub
		var subPic = new cc.MenuItemImage(gpNamespace.sctc.Sctc_Sub,gpNamespace.sctc.Sctc_Sub,this.subCallback,this);
		subPic.attr({
			x:140,
			y:172,
			anchorX:0,
			anchorY:0
		});
		subPic.setUserData(this);

		//add
		var addPic = new cc.MenuItemImage(gpNamespace.sctc.Sctc_Add,gpNamespace.sctc.Sctc_Add,this.addCallback,this);
		addPic.attr({
			x:518,
			y:172,
			anchorX:0,
			anchorY:0
		});
		addPic.setUserData(this);

		//buy
		var buyPic = new cc.MenuItemImage(gpNamespace.tankuang.goumai,gpNamespace.tankuang.goumai,this.buyCallback,this);
		buyPic.attr({
			x:258,
			y:30,
			anchorX:0,
			anchorY:0
		});
		buyPic.setUserData(this);

		//加减菜单
		var tcmenu = new cc.Menu(minPic,maxPic,subPic,addPic);
		tcmenu.attr({
			x:0,
			y:0,
			anchorX:0,
			anchorY:0
		});
		background.addChild(tcmenu);
		var buymenu = new cc.Menu(buyPic);
		buymenu.attr({
			x:0,
			y:0,
			anchorX:0,
			anchorY:0
		});
		background.addChild(buymenu);
		
		if(this.page == 1){
			tcmenu.visible = false;
		}
	},
	sub2minCallback:function(sender){
//		cc.log("sub2minCallback");
		self = sender.getUserData();
		if(self.num > 1 ){
			self.removeChildByTag(110);
			self.num = 1;
			var num = new tyNamespace.NumLayer(1,21,13,"sz_cdd_js_");
			num.setTag(110)
			num.attr({
				x:645,
				y:300,
			});
			self.addChild(num);
			this.reloadPrice();
		}
	},
	add2maxCallback:function(sender){
//		cc.log("add2maxCallback");
		self = sender.getUserData();
		if(self.num < 99 ){
			self.removeChildByTag(110);
			self.num = 99;
			var num = new tyNamespace.NumLayer(99,21,13,"sz_cdd_js_");
			num.setTag(110)
			num.attr({
				x:645,
				y:300,
			});
			self.addChild(num);
			this.reloadPrice();
		}
	},
	subCallback:function(sender){
//		cc.log("subCallback");
		self = sender.getUserData();
		if(self.num > 1 ){
			self.removeChildByTag(110);
			self.num = self.num - 1;
			var num = new tyNamespace.NumLayer(self.num,21,13,"sz_cdd_js_");
			num.setTag(110)
			num.attr({
				x:645,
				y:300,
			});
			self.addChild(num);
			this.reloadPrice();
		}
	},
	addCallback:function(sender){
//		cc.log("addCallback");
		self = sender.getUserData();
		if(self.num < 99 ){
			self.removeChildByTag(110);
			self.num = self.num + 1;
			var num = new tyNamespace.NumLayer(self.num,21,13,"sz_cdd_js_");
			num.setTag(110)
			num.attr({
				x:645,
				y:300,
			});
			self.addChild(num);
			this.reloadPrice();
		}
	},
	buyCallback:function(sender){
		cc.log("buyCallback");
		self = sender.getUserData();
		var WarningSectencesIndex = tyNamespace.WarningSectencesIndex.NoVoucher;
		var isEnough = true;
		if(self.goods[6]==1){//钻石
			if(userInfo.diamond < self.goods[2] * this.num){
				isEnough = false;
				WarningSectencesIndex = tyNamespace.WarningSectencesIndex.NoDiamond;//设为钻石
			}
		}else if(self.goods[6]==0){//金币
			if(userInfo.gold < self.goods[2] * this.num){
				isEnough = false;
				WarningSectencesIndex = tyNamespace.WarningSectencesIndex.NoGold;
			}
		}else{//兑换券
			if(userInfo.voucher < self.goods[2] * this.num){
				isEnough = false;
			}
		}
		if(!isEnough){
			var runningScene = cc.director.getRunningScene();
			var modelLayerCancelable = new tyNamespace.ModelLayerCancelable();
			var modelLayer = new tyNamespace.ModelLayer(70);
			modelLayer.setTouchArea(cc.size(695, 500), cc.p(288, 125));
			modelLayerCancelable.addChild(modelLayer);
			runningScene.addChild(modelLayerCancelable, 10);
			var jumpLayer = new tyNamespace.WarningLayer(1,WarningSectencesIndex);
			jumpLayer.attr({
				//左上角坐标
				x: 0,
				y: cc.winSize.height,
			});
			modelLayer.addChild(jumpLayer);
			tyNamespace.AnimationManager.nodeJumpShow(jumpLayer, -cc.winSize.height);
		}else{
			if(self.page == 1){
				xinyou.netManager.buyGoodsSw(self.goods[0]);
			}else if(self.page == 2){
				xinyou.netManager.buyGoodsJb(self.goods[0],self.num);
			}else if(self.page == 3){
				xinyou.netManager.buyGoodsDj(self.goods[0],self.num);
			}
		}
		self.getParent().getParent().removeFromParent(true);//移除罩子
	},
	reloadPrice:function(){
		this.price.reloadNum(this.goods[2] * this.num);
	}
})